/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.brands.application.ics.facade;

import br.com.brands.application.ics.beans.BrandsBeans;
import br.com.brands.application.ics.delegate.BrandsDelegate;
import java.util.List;
import javax.ejb.EJBException;
import javax.ejb.Stateless;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.hibernate.HibernateException;

/**
 *
 * @author ppacheco
 */
@Stateless(name = "BrandsFacadeBean", mappedName = "BrandsFacadeBean")
public class BrandsFacadeBean implements BrandsFacadeBeanLocal {

    private static final Logger log = Logger.getLogger("br.com.brands.application.ics.facade.BrandsFacadeBean");

    public BrandsFacadeBean() {
        log.log(Level.INFO, "Loading BrandsFacadeBean - EJB Facade Layer Level");
    }

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    @Override
    public BrandsBeans save(BrandsBeans brands) throws EJBException {

        BrandsBeans objRef = null;

        try {
            objRef = BrandsDelegate.getInstance().save(brands);
        } catch (InstantiationException e) {
            log.log(Level.ERROR, e.getMessage(), e);
        } catch (HibernateException e) {
            log.log(Level.ERROR, e.getMessage(), e);
        }
        return objRef;
    }

    @Override
    public BrandsBeans saveOrUpdate(BrandsBeans brands) throws EJBException {

        BrandsBeans objRef = null;

        try {
            objRef = BrandsDelegate.getInstance().saveOrUpdate(brands);
        } catch (InstantiationException e) {
            log.log(Level.ERROR, e.getMessage(), e);
        } catch (HibernateException e) {
            log.log(Level.ERROR, e.getMessage(), e);
        }
        return objRef;
    }

    @Override
    public BrandsBeans delete(BrandsBeans brands) throws EJBException {

        BrandsBeans objRef = null;

        try {
            objRef = BrandsDelegate.getInstance().delete(brands);
        } catch (InstantiationException e) {
            log.log(Level.ERROR, e.getMessage(), e);
        } catch (HibernateException e) {
            log.log(Level.ERROR, e.getMessage(), e);
        }
        return objRef;
    }

    @Override
    public BrandsBeans findByID(BrandsBeans brands, Long id, boolean lock)
            throws EJBException {

        BrandsBeans objRef = null;

        try {
            objRef = BrandsDelegate.getInstance().findByID(brands, id, lock);
        } catch (InstantiationException e) {
            log.log(Level.ERROR, e.getMessage(), e);
        } catch (HibernateException e) {
            log.log(Level.ERROR, e.getMessage(), e);
        }
        return objRef;
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<BrandsBeans> findAll(BrandsBeans brands) throws EJBException {

        List<BrandsBeans> list = null;

        try {
            list = (List<BrandsBeans>) BrandsDelegate.getInstance().save(brands);
        } catch (InstantiationException e) {
            log.log(Level.ERROR, e.getMessage(), e);
        } catch (HibernateException e) {
            log.log(Level.ERROR, e.getMessage(), e);
        }
        return list;
    }
}